package com.simtop.service.impl;

import com.simtop.dao.ApiMapper;
import com.simtop.pojo.User;
import com.simtop.pojo.wddata.*;
import com.simtop.pojo.wddata.UserVo;
import com.simtop.service.ApiService;
import com.simtop.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


@Service
public class ApiServerImpl implements ApiService {

    @Autowired
    private ApiMapper apiMapper;


    @Override
    public void saverapi(String data, String createtime, String plant) {
          apiMapper.saverapi(data,createtime,plant);
    }

    @Override
    public api findAlldevice() {
        return apiMapper.findAlldevice();
    }

    @Override
    public boolean managedata(List<WdDate> lastDate, String plant) {
        for (WdDate aa:lastDate
             ) {


            aa.setDeviceplant(plant);
            Integer tss = aa.getTss();
            String timestampString = String.valueOf(tss);
            //String formats = "yyyy-MM-dd HH:mm:ss";
            Long timestamp = Long.parseLong(timestampString) * 1000;
            Date date = new Date(timestamp);
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            String formatdata = df.format(date);
            aa.setFormatData(formatdata);
            //     System.out.println(date);
            aa.setDevicetime(date);
            //System.out.println(date);
            //日期格式字符串
            //String dateStr = new SimpleDateFormat(formats, Locale.CHINA).format(new Date(timestamp));
            //当然 没有id是不行的 取一个万能id作为链表查询
            //温湿度 id 1
            //核心
            if(aa.getTnm().contains("WSD")){
                //说明他是温湿度
                //拆解string
                //WSD_1_WD
                String tnm = aa.getTnm();
                Integer deviceid = Integer.valueOf(tnm.split("_")[1]);
                //System.out.println(deviceid);
                aa.setDeviceid(deviceid);
                aa.setDevicename("WSD_"+ deviceid);
                //判断类型是什么
                if(tnm.endsWith("WD")){
                    aa.setDevicetype("温度");
                    Float val = aa.getVal();
                    aa.setVal(val/10);
                }else if(tnm.endsWith("SD")){
                    aa.setDevicetype("湿度");
                    Float val = aa.getVal();
                    aa.setVal(val/10);
                }
            }else if(aa.getTnm().contains("LZ")){
                String tnm = aa.getTnm();
                Integer deviceid = Integer.valueOf(tnm.split("_")[1]);
                //System.out.println(deviceid);
                aa.setDeviceid(deviceid);
                aa.setDevicename("LZ_"+ deviceid);
                //获取类型
                if(tnm.endsWith("YW")){
                    aa.setDevicetype("颗粒度0.5");
                    Float val = aa.getVal();
                    aa.setVal(val *  353);
                }
                if(tnm.endsWith("SW")){
                    aa.setDevicetype("颗粒度5");
                    Float val = aa.getVal();
                    aa.setVal(val * 353);
                }
            }else if(aa.getTnm().contains("FS")){
                String tnm = aa.getTnm();
                Integer deviceid = Integer.valueOf(tnm.split("_")[1]);
                //System.out.println(deviceid);
                aa.setDeviceid(deviceid);
                aa.setDevicename("FS_"+ deviceid);
                //获取类型
                if(tnm.endsWith("FS")){
                    aa.setDevicetype("风速");
                    Float val = aa.getVal();
                    aa.setVal(val/1000);
                }

            }
            else if(aa.getTnm().contains("YC")){
                String tnm = aa.getTnm();
                Integer deviceid = Integer.valueOf(tnm.split("_")[1]);
                //System.out.println(deviceid);
                aa.setDeviceid(deviceid);
                aa.setDevicename("YC_"+ deviceid);
                //获取类型
                if(tnm.endsWith("YC")){
                    aa.setDevicetype("压差");
                    Float val = aa.getVal();
                    aa.setVal(val);
                }

            }

            aa.setDevicetime(new Date());
        }


        boolean  savedata = apiMapper.savedata(lastDate);

        return  savedata;

    }

    @Override
    public List<MainTain> findAlldeviceList(String op,String or,String deviceName,String deviceType) {
        return apiMapper.findAlldeviceList(op,or,deviceName,deviceType);
    }

    @Override
    public WdDate findDeviceValue(int deviceId,String testType) {
        return apiMapper.findDeviceValue(deviceId,testType);
    }

    @Override
    public WdDate findDeviceStatusValue(int deviceId) {
        return apiMapper.findDeviceStatusValue(deviceId);
    }

    @Override
    public void updateDevice(Integer deviceId, String devicepolicelistOne, String devicepolicelistTwo,
                             String devicepolicelistThree, String devicepolicelistFor, String testLocation,
                             Integer deviceNormalup, Integer deviceNormaldown, Integer devicePoliceup,
                             Integer devicePolicedown,String testType ) {
 apiMapper.updateDevice(deviceId,devicepolicelistOne,devicepolicelistTwo,devicepolicelistThree,devicepolicelistFor,
                                    testLocation,deviceNormalup,deviceNormaldown,devicePoliceup,devicePolicedown,testType);
    }

    @Override
    public List<MainTain> findAlldeviceListAll() {
        return apiMapper.findAlldeviceListAll();
    }

    @Override
    public void updateDeviceList(List<MainTain> findAlldeviceListAll) {
        apiMapper.updateDeviceList(findAlldeviceListAll);
    }

    @Override
    public void updateDeviceDataList(ArrayList<MonitoringDataVo> monitoringDataVos) {
        apiMapper.updateDeviceDataList(monitoringDataVos);
    }

    @Override
    public List<MonitoringDataVo> findAlldeviceMonitor(String op, String px) {
        return    apiMapper.findAlldeviceMonitor(op,px);
    }

    @Override
    public List<MonitoringDataVo> findAlldeviceListAllBystatus(String op, String px, String readTimeBegins, String readTimeEnds, String deviceNumber, String testType) {
        return apiMapper.findAlldeviceListAllBystatus(op,px,readTimeBegins,readTimeEnds,deviceNumber,testType);
    }

    @Override
    public List<MonitoringDataVo> findAlldeviceListAllBystatus2() {
        return apiMapper.findAlldeviceListAllBystatus2();
    }

    @Override
    public List<MonitoringDataVo> findAlldeviceListAllBystatus3(ArrayList<Integer> sqsyidlist) {
        return apiMapper.findAlldeviceListAllBystatus3(sqsyidlist);
    }

    @Override
    public void updeviceStatus(Integer policeControl, String testType, Integer deviceId) {
        apiMapper.updeviceStatus(policeControl,testType,deviceId);
    }

    @Override
    public String finNewDevice() {
      return   apiMapper.finNewDevice();
    }

    @Override
    public MainTain findBynameAndidAndType(Integer i) {
        return apiMapper.findBynameAndidAndType(i);
    }

    @Override
    public void insertGroupBy(String groupName, int i, String deviceName, Integer deviceId, String testType, int findOneTypeId) {
        apiMapper.insertGroupBy(groupName,i,deviceName,deviceId,testType,findOneTypeId);
    }

    @Override
    public List<GroupUp> finAllGroupUp(String groupId) {
        return apiMapper.finAllGroupUp(groupId);
    }

    @Override
    public void insertGroupType(String groupName) {
        apiMapper.insertGroupType(groupName);
    }

    @Override
    public void insertGroupType1(String groupName) {
        apiMapper.insertGroupType1(groupName);
    }

    @Override
    public int findOneTypeId(String groupName) {
        return apiMapper.findOneTypeId(groupName);
    }

    @Override
    public int findOneTypeId1(String groupName) {
        return apiMapper.findOneTypeId1(groupName);
    }

    @Override
    public int finOnly(String groupName) {
        return apiMapper.finOnly(groupName);
    }

    @Override
    public List<GroupType> groupType() {
        return apiMapper.groupType();
    }

    @Override
    public List<OnlyType> findAlldeviceListAll2() {
        return apiMapper.findAlldeviceListAll2();
    }

    @Override
    public List<String> findAllTab(int id) {
        return apiMapper.findAllTab(id);
    }

    @Override
    public List<String> finAllU3dTab() {
        return apiMapper.finAllU3dTab();
    }

    @Override
    public void updateAllGroupName(String groupName,int groupid) {
         apiMapper.updateAllGroupName(groupName,groupid);
    }

    @Override
    public void updateAllGroupName1(String groupName,int groupid) {
        apiMapper.updateAllGroupName1(groupName,groupid);
    }

    @Override
    public void updateAllgoup(String groupName , Integer groupid) {
        apiMapper.updateAllgoup(groupName,groupid);
    }

    @Override
    public void updateAllgoup1(String groupName , Integer groupid) {
        apiMapper.updateAllgoup1(groupName,groupid);
    }

    @Override
    public List<GroupType> groupTypeUser() {
        return apiMapper.groupTypeUser();
    }

    @Override
    public int finOnly1(String groupName) {
        return apiMapper.finOnly1(groupName);
    }

    @Override
    public List<Integer> finByid(Integer id) {
        return apiMapper.finByid(id);
    }

    @Override
    public UserVo findOne(Integer i) {
        return apiMapper.findOne(i);
    }

    @Override
    public void insertGroupBy1(Integer i, String name, String rolename, int findOneTypeId) {
         apiMapper.insertGroupBy1(i,name,rolename,findOneTypeId);
    }

    @Override
    public List<GroupUserTypes> finAllGroupUp2(String groupId) {
        return apiMapper.finAllGroupUp2(groupId);
    }

    @Override
    public void deleteGroup(Integer groupid) {
        apiMapper.deleteGroup(groupid);
    }

    @Override
    public void deleteGroup1(Integer groupid) {
        apiMapper.deleteGroup1(groupid);
    }

    @Override
    public List<wduserGroupBy> findAllGroupByid() {
       return apiMapper.findAllGroupByid();
    }

    @Override
    public List<wduserGroupBy> findAllGroupByid2() {
        return apiMapper.findAllGroupByid2();
    }

    @Override
    public wduserGroupByDao finOnewdGroupById(Integer id) {
        return apiMapper.finOnewdGroupById(id);
    }

    @Override
    public List<User> findAllUser(String groupChead) {
        return apiMapper.findAllUser(groupChead);
    }

    @Override
    public void updateAllgroupByid(String types, Integer id, String name) {
        apiMapper.updateAllgroupByid(types,id,name);
    }

    @Override
    public String findOneGroupByOne(Integer id) {
        return apiMapper.findOneGroupByOne(id);
    }

    @Override
    public String findOneGroupByOne2(Integer id) {
        return apiMapper.findOneGroupByOne2(id);
    }

    @Override
    public void cheageUser(String groupchead,String name) {
        apiMapper.cheageUser(groupchead,name);
    }

    @Override
    public void cheageUser2(String groupchead,String name) {
        apiMapper.cheageUser2(groupchead,name);
    }

    @Override
    public void deletOne(Integer id, String type) {
        apiMapper.deletOne(id , type);
    }

    @Override
    public void updateBackendUser(User user) {
        apiMapper.updateBackendUser(user);
    }

    @Override
    public void insertGroupbubu(String types , String name) {
        apiMapper.insertGroupbubu(types,name);
    }

    @Override
    public List<MainTain> findAlldeviceList2(String deviceName, String deviceType) {
        return apiMapper.findAlldeviceList2(deviceName,deviceType);
    }

    @Override
    public void getStatus(Integer id) {
        apiMapper.getStatus(id);
    }

    @Override
    public void getStatusList(ArrayList<Integer> sqsyidlist) {
        apiMapper.getStatusList(sqsyidlist);
    }

    @Override
    public void getStatusList2(ArrayList<Integer> sqsyidlist) {
        apiMapper.getStatusList2(sqsyidlist);
    }

    @Override
    public void safeData(Integer status) {
        apiMapper.safeData(status);
    }

    @Override
    public allTypeVo getsafeData() {
        return apiMapper.getsafeData();
    }

    @Override
    public void massageStatus(String cont, Integer status) {
        apiMapper.massageStatus(cont,status);
    }

    @Override
    public StatusVo getmassageStatus() {
        return apiMapper.getmassageStatus();
    }

    @Override
    public messageVo getmassageStatus2() {
        return apiMapper.getmassageStatus2();
    }

    @Override
    public int lastGroup(Integer ids) {
        return apiMapper.lastGroup(ids);
    }

    @Override
    public String findRoleName(Integer roleId) {
        return  apiMapper.findRoleName(roleId);
    }

    @Override
    public List<String> findwdList(String vs) {
        return apiMapper.findwdList(vs);
    }

    @Override
    public List<String> findwdList2(String formatBegin , String formatEnd) {
        return apiMapper.findwdList2(formatBegin , formatEnd);
    }

    @Override
    public List<MainTain> findAlldeviceListAllnew(String devicetype) {
        return apiMapper.findAlldeviceListAllnew(devicetype);
    }

    @Override
    public Integer findvalue(String as2, String deviceNumber) {
        return apiMapper.findvalue(as2,deviceNumber);
    }

    @Override
    public List<String> findviewData() {
        return apiMapper.findviewData();
    }

    @Override
    public void yjController(Integer yjControl, String testType, Integer deviceId) {
        apiMapper.yjController(yjControl,testType,deviceId);
    }

    @Override
    public void changemaintime(Integer deviceId, Date mainTime) {
        apiMapper.changemaintime(deviceId,mainTime);
    }

    @Override
    public void timeCount(Integer timeCount) {
        apiMapper.timeCount(timeCount);
    }

    @Override
    public Integer finOneTimeCount() {
        return apiMapper.finOneTimeCount();
    }

    @Override
    public ApiVo finnewData() {
      return    apiMapper.finnewData();
    }

    @Override
    public Integer findTtimeCount() {
        return apiMapper.findTtimeCount();


    }

    @Override
    public List<String> sixday() {
        return apiMapper.sixday();
    }

    @Override
    public List<String> findSixDay(String vbs) {
        return apiMapper.findSixDay(vbs);
    }

    @Override
    public List<String> findSixDay2(String vbs) {
        return apiMapper.findSixDay2(vbs);
    }


}
